#include <iostream>
#include <map>

int n;

int main()
{
	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	while (T--) {
		std::cin >> n;
		std::map<int, int> p;
		for (int i = 0, x; i < n; i++) {
			std::cin >> x;
			p[x]++;
		}
		int ans = 0, id = -1;
		for (std::map<int, int>::iterator it = p.begin(); it != p.end(); it++) {
			if (it->second > ans || (it->second == ans && it->first > id)) {
				id = it->first;
				ans = it->second;
			}
		}
		std::cout << id << '\n';
	}
}

